package com.alpsoft.spotcheck.util;

import android.content.Context;
import android.os.RemoteException;

import com.iflytek.speech.ISpeechModule;
import com.iflytek.speech.InitListener;
import com.iflytek.speech.SpeechConstant;
import com.iflytek.speech.SpeechSynthesizer;
import com.iflytek.speech.SpeechUtility;
import com.iflytek.speech.SynthesizerListener;

/**
 * @author zz.han 2015年5月18日 下午8:59:18 
 *  使用说明。 
 * 1.需要把speechcloud语音包文件夹放在sd卡根目录下。
 * 2.需安装xfyy+.apk
 * 3.new TtsHelper(Context c)需要在onCreat下。
 * 4.调用 .speak(String s)
 */
public class TtsHelper {
	private Context context;
	private SpeechSynthesizer mTts;

	public TtsHelper(Context context) {
		this.context = context;
		initTTS();
	}

	// 说话
	public void speak(String s) {
		mTts.startSpeaking(s, mTtsListener);
	}

	// 结束TTS
	public void endSpeech() {
		mTts.stopSpeaking(mTtsListener);
		mTts.destory();
	}

	// 初始化
	private void initTTS() {
		SpeechUtility.getUtility(context).setAppid("MySpeechDemo");
		mTts = new SpeechSynthesizer(context, mTtsInitListener);
		mTts.setParameter(SpeechConstant.ENGINE_TYPE, "local");
	}

	private InitListener mTtsInitListener = new InitListener() {

		@Override
		public void onInit(ISpeechModule arg0, int arg1) {
			// TODO Auto-generated method stub

		}
	};

	private SynthesizerListener mTtsListener = new SynthesizerListener.Stub() {

		@Override
		public void onSpeakResumed() throws RemoteException {
			// TODO Auto-generated method stub

		}

		@Override
		public void onSpeakProgress(int arg0) throws RemoteException {
			// TODO Auto-generated method stub

		}

		@Override
		public void onSpeakPaused() throws RemoteException {
			// TODO Auto-generated method stub

		}

		@Override
		public void onSpeakBegin() throws RemoteException {
			// TODO Auto-generated method stub

		}

		@Override
		public void onCompleted(int arg0) throws RemoteException {
			// TODO Auto-generated method stub

		}

		@Override
		public void onBufferProgress(int arg0) throws RemoteException {
			// TODO Auto-generated method stub

		}
	};
}
